<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Page super utilisateur</title>
	
  	<link rel="stylesheet" href="<c:url value="/resources/Styles/styles.css"/>"/>
	<script src="<c:url value="/resources/js/jquery-1.8.3.js"/>"></script>

  	<script>

  	function rechercherParStatut(){
		$('#form').attr('action', 'rechercherParStatut');
		$('#form').submit();
  	}

  	function supprimer(id){
  		if(confirm("Etes-vous sur de vouloir supprimer cette application?")){
			$('#idApp').val(id);
			$('#form').attr('action', 'supprimer');
			$('#form').submit();
  		}
	}

	function valider(id){
		if(confirm("Etes-vous sur de vouloir modifier cette application?")){
			$('#idApp').val(id);
			$('#form').attr('action', 'valider');
			$('#form').submit();
		}
	}
	

	function ajouter(id){

		if(confirm("Etes-vous sur de vouloir ajouter cette application?")){
			$('#form').attr('action', 'ajouter');
			$('#form').submit();
  		}
	}
	
</script>
  	
</head>
<body>

<form:form method="post" action="validerTout" commandName="ApplicationSuperUserForm" id="form">

<table id="tableView" align="center" border="1" width="1000">

	<tr>
		<th width="20%">Logo</th>
		<th width="25%">Libelle</th>
		<th width="25%">Lien</th>
		<th width="10%">Etat</th>
		<th width="10%">Montant</th>
		<th width="10%">Actions</th>
	</tr>
	<tr>
		<td><form:input path="logoNew" id="logo"/></td>
		<td><form:input path="libelleNew" id="libelle"/></td>
		<td><form:input path="lienNew" id="lien"/></td>
		<td>
			<form:select path="statutNew" id="statut">
			   <form:option value="0" label="--- Select ---"/>
			   <form:option value="1" label="Non commencée"/>
			   <form:option value="2" label="Disponible"/>
			   <form:option value="3" label="Epuisée"/>
			</form:select>			
		</td>
		<td><form:input path="montantNew" id="montant"/></td>
		<td>
			<a onclick="javascript:ajouter()">
				<img src="<c:url value="/resources/img/add.png"/>" title="valider">
			</a>
			
		</td>
	</tr>
</table>

<div align="center"><h3><spring:message code="index.listeApps"/></h3></div>

<table id="tableView" align="center" border="1" width="1000">

	<tr>
		<td colspan="2">
			<form:select path="statutRecherche" id="statutRecherche">
			   <form:option value="0" label="--- All ---"/>
			   <form:option value="1" label="Non commencée"/>
			   <form:option value="2" label="Disponible"/>
			   <form:option value="3" label="Epuisée"/>
			</form:select>	
			<a onclick="javascript:rechercherParStatut()">
				<img src="<c:url value="/resources/img/rechercher.png"/>" title="rechercher">
			</a>
		</td>
		<td colspan="4" align="right"><form:button>Valider la modification</form:button></td>
	</tr>
	<tr>
		<th width="20%">Logo</th>
		<th width="25%">Libelle</th>
		<th width="25%">Lien</th>
		<th width="10%">Etat</th>
		<th width="10%">Montant</th>
		<th width="10%">Actions</th>
	</tr>

	<c:forEach items="${listApplication}" var="application">
	<tr >

		<td>
			<a onclick="javascript:todo();">
				<img src= "<c:url value="/resources/img/participations/${application.image}" />" title="rechercher"/>
			</a>
			<form:input path="mapLogo[${application.id}]" id="logo_${application.id}"/>
		</td>

		<td width="25%">
			<form:input path="mapLibelle[${application.id}]" id="libelle_${application.id}"/>
   		</td>
		<td width="25%">
			<form:input path="mapLien[${application.id}]" id="lien_${application.id}"/>
   		</td>
   		<td width="10%">
			<form:select path="mapStatuts[${application.id}] " id="statut_${application.id}">
			   <form:option value="0" label="--- Select ---"/>
			   <form:option value="1" label="Non commencée"/>
			   <form:option value="2" label="Disponible"/>
			   <form:option value="3" label="Epuisée"/>
			</form:select>			
		</td>
		
		<td width="10%">
			<form:input path="mapMontant[${application.id}]" id="montant_${application.id}"/>
		</td>
		<td width="10%">
			<a onclick="javascript:valider(${application.id})">
				<img src="<c:url value="/resources/img/valider.png"/>" title="valider">
			</a>
			<a onclick="javascript:supprimer(${application.id})">
				<img src="<c:url value="/resources/img/delete.png"/>" title="supprimer">
			</a>
		</td>
	
	</tr>
	</c:forEach>

</table>

<form:hidden path="idApp" id="idApp"/>

</form:form>
</body>
</html>